#ifndef __LEVEL
#define __LEVEL

#include "list.h"
#include "player.h"

using namespace std;

class Level
{
  private:
    int currentLevel;
    int timerCounter;

  public:
    Level()
    {
        currentLevel = 1;
    }

    void levelSetup(list<Player>& playerList, list<Enemy>& enemyList, list<Centi>& centipedeList, Uint32 frame)
    {
        timerCounter = 0;
        enemyList.erase();
        centipedeList.erase();
        playerList[0].setIsDead( false);

        if(currentLevel == 1)
        {
            for(int i=0; i < playerList.getSize(); i++)
            {
                playerList[i].setIsDead(false);
                playerList[i].setMaxAmmo(1);
            }
            createEnemies( enemyList, "mushroom", 25);
            centipedeList.pushBack(Centi());
        }
        else if(currentLevel == 2)
        {
            for(int i=0; i < playerList.getSize(); i++)
            {
                playerList[i].setIsDead(false);
                playerList[i].setMaxAmmo(2);
            }
            createEnemies( enemyList, "mushroom", 29);
            centipedeList.pushBack(Centi());
        }
        else if(currentLevel == 3)
        {
            for(int i=0; i < playerList.getSize(); i++)
            {
                playerList[i].setIsDead(false);
                playerList[i].setMaxAmmo(2);
            }
            createEnemies( enemyList, "mushroom", 32);
            centipedeList.pushBack(Centi());
        }
        else if(currentLevel == 4)
        {
            for(int i=0; i < playerList.getSize(); i++)
            {
                playerList[i].setIsDead(false);
                playerList[i].setMaxAmmo(3);
            }
            createEnemies( enemyList, "mushroom", 35);
            centipedeList.pushBack(Centi());
            centipedeList.pushBack(Centi());
        }
        else
        {
            for(int i=0; i < playerList.getSize(); i++)
            {
                playerList[i].setIsDead(false);
                playerList[i].setMaxAmmo(5);
            }
            createEnemies( enemyList, "mushroom", 42);
            centipedeList.pushBack(Centi());
            centipedeList.pushBack(Centi());
            centipedeList.pushBack(Centi());
        }
    }

    void levelUpdate(list<Player>& playerList, list<Enemy>& enemyList, list<Centi>& centipedeList, Uint32 frame, int& gameState)
    {
        if(currentLevel == 1)
        {
            //createEnemiesQueue(frame, enemyList, "spiderLeft", 1, 540, -1);
            //createEnemiesQueue(frame+185, enemyList, "spiderRight", 1, 370, -1);
            //createEnemiesQueue(frame, enemyList, "flea", 2, 150, -1);
            createEnemiesQueue(frame, enemyList, "scorpionLeft", 1, 600, -1);
            createEnemiesQueue(frame, enemyList, "scorpionRight", 1, 500, -1);
        }
        else if(currentLevel == 2)
        {
            createEnemiesQueue(frame, enemyList, "spiderLeft", 1, 500, -1);
            createEnemiesQueue(frame+350, enemyList, "spiderRight", 1, 370, -1);
            createEnemiesQueue(frame, enemyList, "flea", 2, 150, -1);
            createEnemiesQueue(frame, enemyList, "scorpionLeft", 1, 500, -1);
            createEnemiesQueue(frame, enemyList, "scorpionRight", 1,450, -1);
        }
        else if(currentLevel == 3)
        {
            createEnemiesQueue(frame, enemyList, "spiderLeft", 1, 440, -1);
            createEnemiesQueue(frame+350, enemyList, "spiderRight", 1, 370, -1);
            createEnemiesQueue(frame, enemyList, "flea", 2, 150, -1);
            createEnemiesQueue(frame, enemyList, "scorpionLeft", 1, 440, -1);
            createEnemiesQueue(frame, enemyList, "scorpionRight", 1,420, -1);
        }
        else if(currentLevel == 4)
        {
            createEnemiesQueue(frame, enemyList, "spiderLeft", 1, 400, -1);
            createEnemiesQueue(frame+350, enemyList, "spiderRight", 1, 340, -1);
            createEnemiesQueue(frame, enemyList, "flea", 2, 100, -1);
            createEnemiesQueue(frame, enemyList, "scorpionLeft", 1, 400, -1);
            createEnemiesQueue(frame, enemyList, "scorpionRight", 1,380, -1);
        }
        else
        {
            createEnemiesQueue(frame, enemyList, "spiderLeft", 1, 300, -1);
            createEnemiesQueue(frame+350, enemyList, "spiderRight", 1, 300, -1);
            createEnemiesQueue(frame, enemyList, "flea", 2, 100, -1);
            createEnemiesQueue(frame, enemyList, "scorpionLeft", 1, 300, -1);
            createEnemiesQueue(frame, enemyList, "scorpionRight", 1,380, -1);
            createEnemiesQueue(frame, enemyList, "mushroom", 1, 500, -1);
        }

        //Level win check
        if(centipedeList.getSize() <= 0)
        {
            currentLevel++;
            levelSetup(playerList, enemyList, centipedeList, frame);
        }

        //Level lose check
        if(playerList[0].getIsDead())
        {
            playerList[0].setLives( playerList[0].getLives() - 1);
            if( playerList[0].getLives() <= 0)
            {
                gameState = 5;
            }
            else
            {
                levelSetup(playerList, enemyList, centipedeList, frame);
            }
        }
    }

    int getCurrentLevel(){return currentLevel;}

    void setLevel(int lvl){currentLevel=lvl;}
};

#endif
